<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\facade\Builder;
use think\facade\View;

class Worker extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Worker';



    public function index(): string
    {
        //构建表格数据
        return Builder::Table()
            ->addColumn(['type' => 'checkbox', 'title' => '全选', 'fixed' => 'left'])
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'name', 'title' => '姓名', 'modify' => '2,input'])
            ->addColumn(['field' => 'mobile', 'title' => '电话', 'modify' => '2,input'])
            ->addColumn(['field' => 'images', 'title' => '缩略图', 'modify' => '2,img,1', 'templet' => '#imagesTpl'])
            ->addColumn(['field' => 'excel', 'title' => '擅长项目', 'modify' => '2,rich_text', 'templet' => '#editorTpl'])
            ->addColumn(['field' => 'sort', 'title' => '排序', 'modify' => '2,input', 'templet' => '#sort_sort', 'width' => 120])
            ->addColumn(['field' => 'create_time', 'title' => '创建时间'])
            ->addColumn(['field' => 'update_time', 'title' => '更新时间'])
            ->addColumn(['field' => 'status', 'title' => '状态', 'templet' => '#status', 'width' => 120])
            ->addColumn(['fixed' => 'right', 'title' => '操作', 'align' => 'center', 'toolbar' => '#barDemo', 'width' => 200])
            ->addRightButtons(['edit' => ['size' => '1000,1000'], 'delete'])
            ->addTopButtons(['add' => ['size' => '1000,1000'], 'deleteAll'])
            ->addSearch([
                ['title', '姓名搜索', 'input,Like'],
            ])
            ->addSwitchTool([['name' => 'status', 'pk' => $this->pk, 'text' => '开启|关闭']])
            ->addSortTool([['name' => 'sort', 'pk' => $this->pk, 'url' => url('update')->build()]])
            ->fetch();
    }

    public function add($tpl = 'worker/edit'): string
    {
        View::assign('form', ['title' => '图片', 'field' => 'images', 'value' => 5]);
        return parent::add($tpl); // TODO: Change the autogenerated stub
    }

    public function edit($id = '', $tpl = 'worker/edit', $info = ''): string
    {
        View::assign('form', ['title' => '图片', 'field' => 'images', 'value' => 5]);
        return parent::edit($id, $tpl, $info); // TODO: Change the autogenerated stub
    }

}
